﻿using Flurl.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Pay.Core {
    public class ShortLinkHelper {
        /// <summary>
        /// 获取短连接
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetShortLink(string url) {
            try {
                string dwz_api_url = "https://dwz.cn/admin/v2/create";
                var resp_str = dwz_api_url.WithHeader("Token", "64decd2e9b0b9f849ee1b3d44b8c3f97").PostJsonAsync(new { url = url }).ReceiveString().Result;
                dwz_resp_model resp_model = resp_str.ToObject<dwz_resp_model>();
                if (resp_model != null && resp_model.Code == 0)
                    return resp_model.ShortUrl;
            }
            catch (Exception) {
            }

            return url;
        }

        public class dwz_resp_model {
            public int Code { get; set; }
            public string ShortUrl { get; set; }
            public string LongUrl { get; set; }
            public string ErrMsg { get; set; }
        }
    }
}